package cn.iocoder.yudao.module.biz.controller.admin.licenceAudit;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.biz.controller.admin.licenceAudit.vo.*;
import cn.iocoder.yudao.module.biz.convert.licenceAudit.BizLicenceAuditConvert;
import cn.iocoder.yudao.module.biz.dal.dataobject.licenceAudit.BizLicenceAuditDO;
import cn.iocoder.yudao.module.biz.service.licenceAudit.BizLicenceAuditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Api(tags = "管理后台 - 审核人员")
@RestController
@RequestMapping("/biz/licence-audit")
@Validated
public class BizLicenceAuditController {

    @Resource
    private BizLicenceAuditService licenceAuditService;

    @PostMapping("/create")
    @ApiOperation("创建审核人员")
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:create')")
    public CommonResult<String> createLicenceAudit(@Valid @RequestBody BizLicenceAuditCreateReqVO createReqVO) {
        return success(licenceAuditService.createLicenceAudit(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新审核人员")
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:update')")
    public CommonResult<Boolean> updateLicenceAudit(@Valid @RequestBody BizLicenceAuditUpdateReqVO updateReqVO) {
        licenceAuditService.updateLicenceAudit(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除审核人员")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:delete')")
    public CommonResult<Boolean> deleteLicenceAudit(@RequestParam("id") String id) {
        licenceAuditService.deleteLicenceAudit(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得审核人员")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:query')")
    public CommonResult<BizLicenceAuditRespVO> getLicenceAudit(@RequestParam("id") String id) {
        BizLicenceAuditDO licenceAudit = licenceAuditService.getLicenceAudit(id);
        return success(BizLicenceAuditConvert.INSTANCE.convert(licenceAudit));
    }

    @GetMapping("/list")
    @ApiOperation("获得审核人员列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:query')")
    public CommonResult<List<BizLicenceAuditRespVO>> getLicenceAuditList(@RequestParam("ids") Collection<String> ids) {
        List<BizLicenceAuditDO> list = licenceAuditService.getLicenceAuditList(ids);
        return success(BizLicenceAuditConvert.INSTANCE.convertList(list));
    }



    @GetMapping("/page")
    @ApiOperation("获得审核人员分页")
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:query')")
    public CommonResult<PageResult<BizLicenceAuditRespVO>> getLicenceAuditPage(@Valid BizLicenceAuditPageReqVO pageVO) {
        PageResult<BizLicenceAuditDO> pageResult = licenceAuditService.getLicenceAuditPage(pageVO);
        return success(BizLicenceAuditConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出审核人员 Excel")
    @PreAuthorize("@ss.hasPermission('biz:licence-audit:export')")
    @OperateLog(type = EXPORT)
    public void exportLicenceAuditExcel(@Valid BizLicenceAuditExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizLicenceAuditDO> list = licenceAuditService.getLicenceAuditList(exportReqVO);
        // 导出 Excel
        List<BizLicenceAuditExcelVO> datas = BizLicenceAuditConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "审核人员.xls", "数据", BizLicenceAuditExcelVO.class, datas);
    }

}
